﻿using Sc.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web;
using System.Web.Http;
using System.Web.Script.Serialization;

namespace Sc.Web.Controllers.WebApi
{
    public class ReturnCarApiController : ApiController
    {
        /// <summary>
        /// 派车纪录服务层
        /// </summary>
        private readonly SendCarRecordService service = new SendCarRecordService();
        /// <summary>
        /// 获取还车纪录
        /// </summary>
        /// <param name="driver">司机ID</param>
        /// <returns></returns>
        [HttpPost]
        public object GetSendCarRecord()
        {
            int driver = Convert.ToInt32(HttpContext.Current.Request["driver"]);
            JavaScriptSerializer json = new JavaScriptSerializer();
            var data = json.Serialize(service.GetSendCarRecord(driver));
            return new HttpResponseMessage { Content = new StringContent(data, System.Text.Encoding.UTF8, "application/json") };
        }
        /// <summary>
        /// 获取数据
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public object GetSCarRecord()
        {
            int bid = Convert.ToInt32(HttpContext.Current.Request["bid"]);
            int type = Convert.ToInt32(HttpContext.Current.Request["type"]);
            var list = service.GetSCRecord(bid, type);
            JavaScriptSerializer json = new JavaScriptSerializer();
            var data = json.Serialize(list);
            return new HttpResponseMessage { Content = new StringContent(data, System.Text.Encoding.UTF8, "application/json") };
        }
        /// <summary>
        /// 保存还车
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public object SaveReturnCar()
        {
            int bid = Convert.ToInt32(HttpContext.Current.Request["bid"]);
            JavaScriptSerializer json = new JavaScriptSerializer();
            var data = json.Serialize(service.SaveReturnCar(bid));
            return new HttpResponseMessage { Content = new StringContent(data, System.Text.Encoding.UTF8, "application/json") };
        }
    }
}
